#include "main.h"
#include "FreeRTOS.h"
#include "task.h"
#include "workqueue.h"
#include "wifi.h"
#include "image.h"
#include "ui.h"

#define LOG_TAG "MAIN"
#define LOG_LVL ELOG_LVL_INFO
#include "elog.h"

void sys_init(void* param)
{
    board_init();
    
    elog_init();
    elog_set_fmt(ELOG_LVL_ASSERT, ELOG_FMT_ALL);
    elog_set_fmt(ELOG_LVL_ERROR, ELOG_FMT_LVL | ELOG_FMT_TAG | ELOG_FMT_TIME | ELOG_FMT_P_INFO);
    elog_set_fmt(ELOG_LVL_WARN, ELOG_FMT_LVL | ELOG_FMT_TAG | ELOG_FMT_TIME | ELOG_FMT_P_INFO);
    elog_set_fmt(ELOG_LVL_INFO, ELOG_FMT_LVL | ELOG_FMT_TAG | ELOG_FMT_TIME);
    elog_set_fmt(ELOG_LVL_DEBUG, ELOG_FMT_LVL | ELOG_FMT_TAG | ELOG_FMT_TIME);
    elog_set_fmt(ELOG_LVL_VERBOSE, ELOG_FMT_TAG);
    elog_start();
    
    log_i("Weather Clock started: %s, %s", __DATE__, __TIME__);
 
    wellcom_image_display();
    esp_wait_ready();
    
    wifi_init();
    wifi_image_display();
    wifi_wait_connect();

    unknown_err_image_display();
    app_init();

    vTaskDelete(NULL);
}

int main(void)
{
    // SCB->VTOR = 0x08010000;
    
    board_lowlevel_init();
    workqueue_init();
    UI_init();
    xTaskCreate(sys_init , "system init", 2048, NULL, 8, NULL);

    vTaskStartScheduler();

    while (1);
}
